﻿using System;
using System.Diagnostics;
using Microsoft.SharePoint;

namespace VPLink2013.Webparts
{
    public class Log
    {
        static public void Write(string error, EventLogEntryType type)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    if (!EventLog.SourceExists("VPLink"))
                    {
                        EventLog.CreateEventSource("VPLink", "");
                    }
                    EventLog.WriteEntry("VPLink", error, type);
                }
                catch
                {
                    // TODO : Handle logging error exception
                }
            });
        }
        static public void Write(Exception e)
        {
            SPSecurity.RunWithElevatedPrivileges(delegate()
            {
                try
                {
                    if (!EventLog.SourceExists("VPLink"))
                    {
                        EventLog.CreateEventSource("VPLink", "");
                    }
                    EventLog.WriteEntry("VPLink", e.Message, EventLogEntryType.Error);
                }
                catch
                {
                    //TODO : Handle logging error exception
                }
            });
        }
    }
}
